package fhp.hlhj.giantfold.adapter

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.support.v4.view.PagerAdapter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import com.bumptech.glide.Glide
import fhp.hlhj.giantfold.R
import fhp.hlhj.giantfold.javaBean.AdvBean
import fhp.hlhj.giantfold.javaBean.PopBean
import fhp.hlhj.giantfold.network.Urls
import java.util.ArrayList
import android.support.v4.content.ContextCompat.startActivity
import com.bumptech.glide.load.resource.drawable.GlideDrawable
import com.bumptech.glide.request.animation.GlideAnimation
import com.bumptech.glide.request.target.SimpleTarget
import com.squareup.picasso.Picasso
import fhp.hlhj.giantfold.javaBean.LunBoBean


/**
 * author: FHP
 * data: on 2017\11\17 0017 17:13
 * E-Mail: 103945089@qq.com
 */
class SpendVPAdp(private val context: Context, private val dats: ArrayList<LunBoBean.DataBean>) : PagerAdapter() {
    override fun isViewFromObject(view: View?, `object`: Any?): Boolean {
        return `object`==view
    }
    override fun instantiateItem(container: ViewGroup?, position: Int): Any {
        val view = LayoutInflater.from(context).inflate(R.layout.spend_vp_item, null)
        val img = view.findViewById<ImageView>(R.id.img)
        if (dats.size!=0){
            Picasso.with(context).load(Urls.BaseUrl+dats[position%dats.size].savepath+dats[position%dats.size].savename).placeholder(R.mipmap.exp2).into(img)
            val bean = dats[position%dats.size]
            img.setOnClickListener {
                if (bean.link.length>0){
                    val intent = Intent()
                    //Intent intent = new Intent(Intent.ACTION_VIEW,uri);
                    intent.setAction("android.intent.action.VIEW")
                    val content_url = Uri.parse(bean.link)
                    intent.setData(content_url)
                    context.startActivity(intent)
                }

            }
        }

        container?.addView(view)
        return view
    }
    override fun destroyItem(container: ViewGroup?, position: Int, `object`: Any?) {
        container?.removeView(`object` as View)
    }

    override fun getCount(): Int = Int.MAX_VALUE
}